<template>
  <div class="itxst">
    <div class="grop_list" v-for="v in list" :key="v">
      {{ v }}
    </div>
  </div>
</template>

<script>
import Sortable from "sortablejs";
import { ref, onMounted } from "vue";
export default {
  setup() {
    const list = ref([1, 2, 3, 4, 5, 6]);
    let newList = [...list.value]
    onMounted(() => {
      const el = document.querySelector('.itxst')
      var ops = {
        delay: 0,
        animation: 150,
        easing: "cubic-bezier(1, 0, 0, 1)",
        chosenClass: "sortable-chosen",
        //拖动结束
        onEnd: function (evt) {
          const {oldIndex,newIndex} = evt
          let item = newList.splice(oldIndex,1)[0]
          newList.splice(newIndex,0,item)
          console.log(newList)
        },
      };
      //初始化
      Sortable.create(el, ops);
    });
    return {
      list,
    };
  },
};
</script>

<style>
.grop_list {
  width: 200px;
  height: 80px;
  line-height: 80px;
  font-size: 40px;
  margin: 0 auto;
  background: skyblue;
  margin-bottom: 10px;
}
.sortable-chosen{
  background: pink;
}
</style>